#include <iostream>
#include <string>
#include <vector>
#include <stack>
using namespace std;


int main(){
    int n;
    cin>>n;
    vector<string> a;
    for (int i=0; i<n; i++){
        string c;
        cin>>c;
        a.push_back(c);
    }
    char l=a[0][1];
    char r=a[0][2];
    stack<char> lstack;
    stack<char> rstack;

    while (1){
        int num1,num2;
        for (i=0; i<n; i++){if (a[i][0]==l)num1=i;if (a[i][1]==r)num2=i;}
        lstack.push_back(a[num1][]);
    }


}